package com.sgb.kjwl.view.ui.adapter.transport;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsOfferUnits;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.util.UserOperating;
import com.swgk.core.util.StringUtil;

import java.util.List;

/**
 * @Author : 熊丽
 * @date :2021/7/20 0020$ 15:54$
 * @Description ://竞价单位适配器$
 */
public class BiddingUnitAdapter  extends BaseQuickAdapter<GoodsOfferUnits, BaseViewHolder>  {
    private boolean isOwner;
    private int tips = 3;
    private int pattern=0;
    private List<GoodsOfferUnits> data;
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public BiddingUnitAdapter(List<GoodsOfferUnits> data,boolean isOwner,int pattern) {
        super(R.layout.activity_bidding_unit_item, data);
        this.isOwner = isOwner;
        this.data = data;
        this.pattern = pattern;
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsOfferUnits item) {
        if (data.size()==0){
            helper.setVisible(R.id.tv_ll,false);
        }
        if (data.size()>0&&data.size()-1==helper.getBindingAdapterPosition()){
            helper.setVisible(R.id.tv_ll,false);
        }
        if (UserOperating.getInstance().isLogged()) {
            helper.setText(R.id.bidding_unit_name, item.getIsSelfOffer() != null && item.getIsSelfOffer() == 1 ? item.getOfferUnit() : (isOwner ? (TextUtils.isEmpty(item.getOfferUnit())?"":item.getOfferUnit()) : StringUtil.left(item.getOfferUnit(), 2)));
        }else {
            helper.setText(R.id.bidding_unit_name, TextUtils.isEmpty(item.getOfferUnit())?"": StringUtil.left(item.getOfferUnit(), 2));
        }
        helper.setText(R.id.bidding_unit_text,item.getIsSelfOffer()!=null&&item.getIsSelfOffer()==1?item.getName():(isOwner?(TextUtils.isEmpty(item.getName())?"":item.getName()): StringUtil.left(item.getName(), 1)));
        if (UserOperating.getInstance().isLogged()){
            helper.setText(R.id.bidding_unit_number,item.getIsSelfOffer()!=null&&item.getIsSelfOffer()==1?item.getTelPhone():(isOwner?( TextUtils.isEmpty(item.getTelPhone())?"":item.getTelPhone()): StringUtil.getPhoneToName(item.getTelPhone())));
        }else {
            helper.setText(R.id.bidding_unit_number, TextUtils.isEmpty(item.getTelPhone())?"":StringUtil.getPhoneToName(item.getTelPhone()));
        }
        if (pattern==1){
            if (!TextUtils.isEmpty(item.getFreight())){
                helper.setText(R.id.bidding_unit_weight,NumberUtil.trim0(item.getFreight()) + item.getFreightUnitType());
            }else {
                helper.setText(R.id.bidding_unit_weight,"/");
            }
        }else {
            if (!TextUtils.isEmpty(item.getAllFreight())){
                helper.setText(R.id.bidding_unit_weight,NumberUtil.trim0(item.getAllFreight())+"元");
            }else {
                helper.setText(R.id.bidding_unit_weight,"/");
            }
        }
        if ( helper.getBindingAdapterPosition()==0) {
            helper.setBackgroundRes(R.id.image_text,R.mipmap.ranking_one);
        }else if (helper.getBindingAdapterPosition()==1){
            helper.setBackgroundRes(R.id.image_text,R.mipmap.ranking_two);
        }else if (helper.getBindingAdapterPosition()==2){
            helper.setBackgroundRes(R.id.image_text,R.mipmap.ranking_three);
        }else {
            tips++;
            helper.setBackgroundRes(R.id.image_text,R.mipmap.ranking_other);
            helper.setText(R.id.image_text,tips+"");
        }
    }
}
